package com.atguigu.juc.locks;

import java.util.concurrent.TimeUnit;

//一个普通方法，一个加锁方法，先打印谁
class Phone3{
    public synchronized void sengEmail(){
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + "正在发邮件...");
    }
    public void hello(){
        System.out.println(Thread.currentThread().getName() + "说Hello...");
    }
}

public class Lock8_3 {
    public static void main(String[] args) {
        Phone3 phone3 = new Phone3();

        new Thread(()->{phone3.sengEmail();},"t1").start();

        try {
            TimeUnit.MILLISECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(()->{phone3.hello();},"t2").start();
    }
}
